﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Services;
using Domain;

namespace WebRole1
{
	public partial class Profile : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				string username = "";
				GetVariables(out username);
				ShowUserDetails(username);
			}
		}


		private void GetVariables(out string username)
		{
			username = "";

			if (!HttpContext.Current.Request.QueryString.AllKeys.Contains("user"))
			{
				Response.Redirect("index");
			}
			else
			{
				username = HttpContext.Current.Request.QueryString["user"].ToString();
			}
		}


		private void ShowUserDetails(string username)
		{
			UserService userServ = new UserService();

			Domain.User u = userServ.getUserDetails(username);

			if (u.ID == null)
			{
				Response.Redirect("~/index");
			}

			lblUsername.Text = u.Name;
			lblUsername2.Text = u.Name;
			lblRegisteredOn.Text = u.RegisteredOn.ToString("D", System.Globalization.CultureInfo.CreateSpecificCulture("nl-NL"));
			lblPostcount.Text = u.PostCount.ToString() + " (gemiddeld " + u.PostsPerDay.ToString() + " per dag)";
			lblLevel.Text = u.LevelNr.ToString() + ". " + u.LevelName;
		}

	}
}